import java.util.Arrays;

public class Test {

    public static void main(String[] args) {

    }

    //null "空引用"
    public static void main4(String[] args) {
        int[] arr = null;
        System.out.println(arr[0]);
    }



    //数组是引用变量（存储在Java虚拟机栈），不直接存储对象本身，而是存储对象在堆中的起始地址
    public static void main3(String[] args) {
        int[] array1 = new int[]{1,2,3,4,5};
        array1[0] = 100;
        array1[1] = 200;

        int[] array2 = new int[3];
        array2[0] = 10;
        array2[1] = 20;
        array2[2] = 30;

        array2 = array1;
        array2[2] = 300;
        array2[3] = 400;
        array2[4] = 500;

        for (int x:array1) {
            System.out.print(x+" ");
        }
    }


    public static void main2(String[] args) {

        int[] array = new int[]{1,2,3,4,5};

        //数组的遍历
        //方法一：数组名.length
        for(int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }

        System.out.println();
        System.out.println("==============");

        //方法二：for each
        for(int x: array) {
            System.out.print(x+" ");
        }

        System.out.println();
        System.out.println("==============");

        //方法三：工具类Arrays
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

    public static void main1(String[] args) {
        //数组的初始化
        //静态初始化
        int[] array = new int[]{1,2,3,4,5};
        //动态初始化
        int[] array1 = new int[10];
        //可分步
        int[] array2;
        array2 = new int[]{5,6,7,8,9};
        //可省略new int[],分步写不可省略
        int[] array3 = {1,4,6,8,0};
        //单个输出
        System.out.println(array[1]);


    }
}
